import logging
import threading
from datetime import datetime
import os,sys
dir_name=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, '../common')
sys.path.insert(0,dir_name)
import readConfig
import os
class Log:
    def __init__(self):
        global proDir, logPath, resultPath
        proDir=readConfig.pro_dir
        resultPath=os.path.join(proDir,"result")
        if not os.path.exists(resultPath):
            os.mkdir(resultPath)
        logPath=os.path.join(resultPath,str(datetime.now().strftime("%Y%m%d_%H%M%S")))
        if not os.path.exists(logPath):
            os.mkdir(logPath)
        self.logger=logging.getLogger()
        self.logger.setLevel(level=logging.INFO)
        handler = logging.FileHandler(os.path.join(logPath,"output.txt"))
        formatter=logging.Formatter('%(asctime)s-%(filename)s-%(module)s-%(funcName)s-%(levelname)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
    def get_logger(self):
        return self.logger

        

class MyLog:
    log =None
    multilog =threading.Lock()
    def __init__(self):
        pass
    def get_log():
        if MyLog.log is None:
            MyLog.multilog.acquire()
            MyLog.log=Log()
            MyLog.multilog.release()
        return MyLog.log